<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            height: 100px;
            width: 100px;
            background: red;
        }
    </style>
</head>
<body>
    <div class="box" style="margin-left: 0;"></div>
</body>
<script>
    let animationId;
    function boxCallback(){
        let boxObj =document.querySelector('.box');
        let toLeft = parseInt(boxObj.style.marginLeft);
        if(toLeft < 200){
            document.querySelector('.box').style.marginLeft = (toLeft + 1) + 'px';
            animationId = requestAnimationFrame(boxCallback);
        }
        else{
            cancelAnimationFrame(animationId);
        }
    }
    animationId = window.requestAnimationFrame(boxCallback);
</script>
</html>